package com.wgcloud;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;


@Configuration
@ConfigurationProperties(prefix = "base")
@Slf4j
public class CommonConfig {


    private String serverUrl = "";

    private String bindIp = "";

    private String wgToken = "";

    @Value("${base.submitInterval:300000}")
    private long submitInterval; // 默认300秒

    public CommonConfig() {
    }

    public String getServerUrl() {
        return serverUrl;
    }

    public void setServerUrl(String serverUrl) {
        this.serverUrl = serverUrl;
    }

    public String getBindIp() {
        return bindIp;
    }

    public void setBindIp(String bindIp) {
        this.bindIp = bindIp;
    }

    public String getWgToken() {
        return wgToken;
    }

    public void setWgToken(String wgToken) {
        this.wgToken = wgToken;
    }

    public long getSubmitInterval() {
        return submitInterval;
    }

    public void setSubmitInterval(long submitInterval) {
        this.submitInterval = submitInterval;
    }

    /**
     * 在类初始化后执行的初始化方法
     * 该方法用于验证提交间隔（submitInterval）的值是否符合要求
     * 如果提交间隔小于300000毫秒（5分钟），则记录错误日志并设置提交间隔为默认值300000毫秒
     */
    @PostConstruct
    public void validateSubmitInterval() {
        if (submitInterval < 300000) {
            log.error("submitInterval 不能小于 300000，当前值为：{}，将使用默认值 300000", submitInterval);
            this.submitInterval = 300000; // 使用默认值
        }
    }
}
